<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            box-sizing: border-box;
        }
        
        body {
            background-color: #111;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100vh;
            overflow: hidden;
            margin: 0;
        }
        
        .container {
            display: flex;
            align-items: center;
            justify-content: center;
            flex-wrap: wrap;
            max-width: 400px;
        }
        
        .square {
            background-color: #1d1d1d;
            box-shadow: 0 0 2px #000;
            height: 16px;
            width: 16px;
            margin: 2px;
            transition: 2s ease;
        }
        
        .square:hover {
            transition-duration: 0s;
        }
    </style>
</head>
<body>
    <div class="container"></div>
    <script>
        let container = document.getElementsByClassName("container")[0]
        let sq = 500
        for(let i = 0; i<sq; i++){
            let square = document.createElement("div")
            square.classList.add("square")
            container.appendChild(square)
            square.addEventListener("mouseover",function(){
                setColor(square)
            })
            square.addEventListener("mouseout",function(){
                removeColor(square)
            })
        }

        function setColor(square){
            let color = getRandomColor();
            square.style.background = color;
            square.style.boxShadow = `0 0 2px ${color}, 0 0 10px ${color}`

        }
        function removeColor(square){
            square.style.background = "#1d1d1d"
            square.style.boxShadow = '0 0 2px #000'
        }

        function getRandomColor(){
            var r = Math.floor(Math.random()*256)
            var g = Math.floor(Math.random()*256)
            var b = Math.floor(Math.random()*256)
            var color = "#" + r.toString(16)+g.toString(16)+b.toString(16)
            return color
        }
    </script>
</body>
</html>